home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / basic / ace24dist.lha / ace24.lha / SUBmods / WBarg / WBarg.b < prev    next >
Text File  |  1996-09-11  |  8KB  |  377 lines

  1. /*
  2. ** WorkBench argument and ToolType subprograms.
  3. **
  4. ** Workbench arguments are contained in the
  5. ** WBStartup structure's ArgList after
  6. ** a program has been launched from the
  7. ** Workbench or an icon with a default tool
  8. ** has been double-clicked.
  9. **
  10. ** The order in which the arguments appear in
  11. ** the list is the same as the order in which
  12. ** the icons (corresponding to the arguments)
  13. ** were selected with the mouse.
  14.  
  15.     Wb Argument Subprograms
  16.     -----------------------
  17.   - WBlaunched returns TRUE or FALSE to indicate whether
  18.     the current program was started from the Workbench        
  19.     or not.
  20.  
  21.   - WBargcount returns the number of arguments
  22.     to a Workbench launched program. The name
  23.     of the program is NOT included in this count.        
  24.  
  25.   - WBarg$(N) returns the Nth Workbench argument
  26.     as a string. The zeroth argument is the
  27.     program's name. Only the name of the argument
  28.     is returned, not it's full path. To obtain
  29.     the latter, use WBargPath$(N).                
  30.  
  31.   - WBargPath$(N) returns the full path of the
  32.     Nth Workbench argument as a string.            
  33.  
  34.  
  35.     ToolType Subprograms
  36.     --------------------
  37.   - ToolTypeVal$(theArg$,toolType$) searches the
  38.     Wb argument's .info file for the specified tooltype
  39.     and returns its value as a string. The null string
  40.     is returned if the tooltype is not found.
  41.  
  42.   - ToolTypeValMatched(toolVal$,value$) returns
  43.     TRUE or FALSE indicating the presence or absence
  44.     of a value in a ToolType string.
  45.  
  46.   - DefaultTool$(theArg$) returns the default tool from
  47.     a Wb argument's .info file. The NULL string is returned
  48.     if no default tool exists or if the argument does not
  49.     correspond to a project icon.
  50.  
  51. ** Author: David J Benn
  52. **   Date: 25th December 1992,
  53. **        29th,30th December 1994,
  54. **       5th March 1995,
  55. **       11th September 1996
  56. */
  57.  
  58. #include <ace/acedef.h>
  59.  
  60. {*
  61. ** External references.
  62. *}
  63. EXTERNAL ADDRESS WBenchMsg    /* Task's WBStartup MESSAGE (from startup.lib). */
  64.  
  65. {*
  66. ** Structure definitions.
  67. ** These could instead be included via the appropriate 
  68. ** header files in ACEinclude:. 
  69. *}
  70. STRUCT WBArg
  71.   ADDRESS wa_Lock
  72.   ADDRESS wa_Name
  73. END STRUCT
  74.  
  75. STRUCT Node
  76.   ADDRESS ln_Succ
  77.   ADDRESS ln_Pred
  78.   BYTE    ln_Type
  79.   BYTE    ln_Pri
  80.   ADDRESS ln_Name
  81. END STRUCT
  82.  
  83. STRUCT _Message
  84.   Node     mn_Node
  85.   ADDRESS  mn_ReplyPort
  86.   SHORTINT mn_Length
  87. END STRUCT
  88.  
  89. STRUCT WBStartup
  90.   _Message sm_Message
  91.   ADDRESS  sm_Process
  92.   ADDRESS  sm_Segment
  93.   LONGINT  sm_NumArgs
  94.   ADDRESS  sm_ToolWindow
  95.   ADDRESS  sm_ArgList
  96. END STRUCT
  97.  
  98. STRUCT DateStamp
  99.   LONGINT ds_Days
  100.   LONGINT ds_Minute
  101.   LONGINT ds_Tick
  102. END STRUCT
  103.  
  104. STRUCT FileInfoBlock
  105.   LONGINT   fib_DiskKey
  106.   LONGINT   fib_DirEntryType
  107.   STRING    fib_FileName SIZE 108
  108.   LONGINT   fib_Protection
  109.   LONGINT   fib_EntryType
  110.   LONGINT   fib_Size
  111.   LONGINT   fib_NumBlocks
  112.   DateStamp fib_Date
  113.   STRING    fib_Comment SIZE 80
  114.   STRING    fib_Reserved SIZE 36
  115. END STRUCT
  116.  
  117. STRUCT _Gadget
  118.   ADDRESS  NextGadget
  119.   SHORTINT LeftEdge
  120.   SHORTINT TopEdge
  121.   SHORTINT Wdth
  122.   SHORTINT Height
  123.   SHORTINT Flags
  124.   SHORTINT Activation
  125.   SHORTINT GadgetType
  126.   ADDRESS  GadgetRender
  127.   ADDRESS  SelectRender
  128.   ADDRESS  GadgetText
  129.   LONGINT  MutualExclude
  130.   ADDRESS  SpecialInfo
  131.   SHORTINT GadgetID
  132.   ADDRESS  UserData
  133. END STRUCT
  134.  
  135. STRUCT DiskObject
  136.   SHORTINT do_Magic
  137.   SHORTINT do_Version
  138.   _Gadget  do_Gadget
  139.   SHORTINT do_Type
  140.   ADDRESS  do_DefaultTool
  141.   ADDRESS  do_ToolTypes
  142.   LONGINT  do_CurrentX
  143.   LONGINT  do_CurrentY
  144.   ADDRESS  do_DrawerData
  145.   ADDRESS  do_ToolWindow
  146.   LONGINT  do_StackSize
  147. END STRUCT
  148.  
  149. {*
  150. ** Shared library functions used by more than one subprogram.
  151. *}
  152. DECLARE FUNCTION ADDRESS GetDiskObject(STRING theIconName) LIBRARY icon
  153. DECLARE FUNCTION FreeDiskObject(ADDRESS diskObject) LIBRARY icon
  154.  
  155. {*
  156. ** Subprogram definitions.
  157. *}
  158. SUB LONGINT WBlaunched EXTERNAL
  159.  
  160.   { Was the program Wb-launched? }
  161.  
  162.   IF WBenchMsg <> NULL THEN
  163.     WBlaunched = TRUE
  164.   ELSE
  165.     WBlaunched = FALSE
  166.   END IF
  167. END SUB
  168.  
  169. SUB SHORTINT WBargcount EXTERNAL
  170. DECLARE STRUCT WBStartup *WBinfo
  171. DECLARE STRUCT WBArg *argptr
  172. SHORTINT n
  173.  
  174.   { Return # of WB args }
  175.  
  176.   WBinfo = WBenchMsg
  177.  
  178.   IF WBinfo <> NULL THEN
  179.     n = WBinfo->sm_NumArgs
  180.     --n  /* don't include WBarg$(0). */
  181.     WBargcount = n
  182.   ELSE
  183.     WBargcount = 0
  184.   END IF
  185. END SUB
  186.  
  187. SUB WBarg$(SHORTINT N) EXTERNAL
  188. DECLARE STRUCT WBStartup *WBinfo
  189. DECLARE STRUCT WBArg *argptr
  190. SHORTINT max_param,count
  191.  
  192.   { Return the Nth WB arg }
  193.  
  194.   WBinfo = WBenchMsg
  195.  
  196.   IF WBinfo <> NULL THEN
  197.     max_param = WBinfo->sm_NumArgs
  198.   ELSE
  199.     max_param = 0
  200.   END IF
  201.  
  202.   IF max_param > 0 AND N <= max_param THEN
  203.     argptr = WBinfo->sm_ArgList
  204.  
  205.     count=0
  206.     WHILE count < N
  207.       argptr = argptr+SIZEOF(WBArg)
  208.       ++count
  209.     WEND
  210.  
  211.     WBarg$ = CSTR(argptr->wa_Name)
  212.   ELSE
  213.     {* Nth argument is non-existent. *}
  214.     WBarg$ = ""
  215.   END IF
  216. END SUB
  217.  
  218. SUB ADDRESS WBargLock(SHORTINT N)
  219. DECLARE STRUCT WBStartup *WBinfo
  220. DECLARE STRUCT WBArg *argptr
  221. SHORTINT max_param,count
  222.  
  223.   { Return the Nth WB arg lock }
  224.  
  225.   WBinfo = WBenchMsg
  226.  
  227.   IF WBinfo <> NULL THEN
  228.     max_param = WBinfo->sm_NumArgs
  229.   ELSE
  230.     max_param = 0
  231.   END IF
  232.  
  233.   IF max_param > 0 AND N <= max_param THEN
  234.     argptr = WBinfo->sm_ArgList
  235.  
  236.     count=0
  237.     WHILE count < N
  238.       argptr = argptr+SIZEOF(WBArg)
  239.       ++count
  240.     WEND
  241.  
  242.     WBargLock = argptr->wa_Lock
  243.   ELSE
  244.     {* Nth lock is non-existent. *}
  245.     WBargLock = NULL
  246.   END IF
  247. END SUB
  248.  
  249. SUB get_abs_path(ADDRESS lock, ADDRESS abspathaddr)
  250. STRING abspath ADDRESS abspathaddr
  251. ADDRESS parentlock
  252. DECLARE STRUCT FileInfoBlock info
  253.  
  254. DECLARE FUNCTION ADDRESS ParentDir LIBRARY dos
  255. DECLARE FUNCTION Examine LIBRARY dos
  256.  
  257.   { recursively construct absolute path }
  258.  
  259.   IF lock <> NULL THEN
  260.     parentlock = ParentDir(lock)
  261.     get_abs_path(parentlock,abspathaddr)
  262.   END IF
  263.  
  264.   IF lock <> NULL THEN
  265.     Examine(lock,info)
  266.     abspath = abspath + info->fib_FileName
  267.     IF parentlock <> NULL THEN
  268.       {* directory *}
  269.       abspath = abspath + "/"
  270.     ELSE
  271.       {* volume *}
  272.       abspath = abspath + ":"
  273.     END IF
  274.   END IF
  275. END SUB
  276.  
  277. SUB WBargPath$(SHORTINT N) EXTERNAL
  278. ADDRESS arglock
  279. STRING  abspath
  280.  
  281.   { Return full path of Nth WB arg }
  282.  
  283.   arglock = WBargLock(N)
  284.  
  285.   IF arglock <> NULL THEN
  286.     get_abs_path(arglock,@abspath)
  287.     WBargPath$ = abspath
  288.   ELSE
  289.     WBargPath$ = ""
  290.   END IF
  291. END SUB
  292.  
  293. SUB ToolTypeVal$(theArg$,toolType$) EXTERNAL
  294. DECLARE STRUCT DiskObject *dobj
  295. ADDRESS toolArray, toolTypeValAddr
  296.  
  297. DECLARE FUNCTION ADDRESS FindToolType(ADDRESS toolArray, STRING toolType) LIBRARY icon
  298.  
  299.   /* Return a tooltype value from a Wb argument's .info file. */
  300.  
  301.   LIBRARY "icon.library"
  302.  
  303.   IF theArg$ <> "" THEN
  304.     dobj = GetDiskObject(theArg$)
  305.     IF dobj = NULL THEN
  306.         tmpVal$ = ""
  307.     ELSE
  308.         toolArray = dobj->do_ToolTypes
  309.         IF toolArray = NULL THEN
  310.       tmpVal$ = ""
  311.         ELSE
  312.           toolTypeValAddr = FindToolType(toolArray,toolType$)
  313.        IF toolTypeValAddr = NULL THEN
  314.         tmpVal$ = ""
  315.       ELSE
  316.         tmpVal$ = CSTR(toolTypeValAddr)
  317.       END IF
  318.      END IF
  319.     END IF
  320.  
  321.     IF dobj <> NULL THEN CALL FreeDiskObject(dobj)
  322.   ELSE
  323.     {* Wb argument is NULL. *}
  324.     tmpVal$ = ""
  325.   END IF
  326.  
  327.   LIBRARY CLOSE "icon.library"
  328.  
  329.   ToolTypeVal$ = tmpVal$
  330. END SUB
  331.  
  332. SUB LONGINT ToolTypeValMatched(toolVal$,value$) EXTERNAL
  333. LONGINT theVal
  334.  
  335. DECLARE FUNCTION SHORTINT MatchToolValue(toolVal$,value$) LIBRARY icon
  336.  
  337.   { Return TRUE/FALSE indicating presence/absence of value in ToolType string }
  338.  
  339.   LIBRARY "icon.library"
  340.  
  341.   theVal = -MatchToolValue(toolVal$,value$)
  342.  
  343.   LIBRARY CLOSE "icon.library"
  344.  
  345.   ToolTypeValMatched = theVal
  346. END SUB
  347.  
  348. SUB DefaultTool$(theArg$) EXTERNAL
  349. DECLARE STRUCT DiskObject *dobj
  350.  
  351.   /* Return the default tool from a Wb argument's .info file. */
  352.  
  353.   LIBRARY "icon.library"
  354.  
  355.   IF theArg$ <> "" THEN
  356.     dobj = GetDiskObject(theArg$)
  357.     IF dobj = NULL THEN
  358.         tmpVal$ = ""
  359.     ELSE
  360.         IF dobj->do_DefaultTool = NULL THEN
  361.       tmpVal$ = ""
  362.         ELSE
  363.       tmpVal$ = CSTR(dobj->do_DefaultTool)
  364.      END IF
  365.     END IF
  366.  
  367.     IF dobj <> NULL THEN CALL FreeDiskObject(dobj)
  368.   ELSE
  369.     {* Wb argument is NULL. *}
  370.     tmpVal$ = ""
  371.   END IF
  372.  
  373.   LIBRARY CLOSE "icon.library"
  374.  
  375.   DefaultTool$ = tmpVal$
  376. END SUB
  377.